//
//  GWItemsCell.m
//  GiftWanted
//
//  Created by lanou on 15/11/7.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "GWItemsCell.h"
#import "UIImageView+WebCache.h"

@implementation GWItemsCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH - 10, 155 - 5)];
        _bgImageView.layer.cornerRadius = 5;
        _bgImageView.layer.masksToBounds = YES;
        
        UIView *greyView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-85, 5, 70, 20)];
        greyView.alpha = 0.5;
        greyView.backgroundColor = [UIColor blackColor];
        greyView.layer.cornerRadius = 10;
        greyView.layer.masksToBounds = YES;
        
        _countLabel = [[GWILView alloc] initWithFrame:CGRectMake(0, 0, 80, 20)];
        _countLabel.img.image = [UIImage imageNamed:@"like"];
        [greyView addSubview:_countLabel];
        
        UIView *gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 155-40, SCREEN_WIDTH-10, 40)];
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.bounds = gradientView.bounds;
        gradientLayer.borderWidth = 0;
        gradientLayer.frame = gradientView.bounds;
        gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.245 alpha:1.000] CGColor], (id)[[UIColor clearColor] CGColor], nil];
        gradientLayer.startPoint = CGPointMake(0, 1);
        gradientLayer.endPoint = CGPointMake(0, 0);
        [gradientView.layer insertSublayer:gradientLayer atIndex:0];
        gradientView.layer.cornerRadius = 5;
        gradientView.layer.masksToBounds = YES;
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH-10, 30)];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [gradientView addSubview:_titleLabel];
        
        [_bgImageView addSubview:greyView];
        [_bgImageView addSubview:gradientView];
        [self.contentView addSubview:_bgImageView];
    }
    return self;
}

- (void)setConfigureModel:(GWItemsModel *)configureModel {
    
    _configureModel = configureModel;
    [_bgImageView sd_setImageWithURL:[NSURL URLWithString:configureModel.cover_image_url]];
    _countLabel.label.text = [NSString stringWithFormat:@"%@", configureModel.likes_count];
    if (configureModel.likes_count == NULL) {
        _countLabel.label.text = @"12345";
    }
    _titleLabel.text = configureModel.title;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
